package com.oldroid.apps.getit.ui;

import org.achartengine.model.CategorySeries;
import org.achartengine.renderer.DefaultRenderer;
import org.achartengine.renderer.SimpleSeriesRenderer;

/**
 * A class that contains useful methods
 * for drawing charts using the AChartEngine
 * Library
 * @author Jervis
 *
 */
public class ChartUtils {
	
	/**
	   * Builds a category renderer to use the provided colors.
	   * 
	   * @param colors the colors
	   * @return the category renderer
	   */
	  public static DefaultRenderer buildCategoryRenderer(int[] colors) {
	    DefaultRenderer renderer = new DefaultRenderer();
	    renderer.setLabelsTextSize(15);
	    renderer.setLegendTextSize(15);
	    renderer.setMargins(new int[] { 20, 30, 15, 0 });
	    for (int color : colors) {
	      SimpleSeriesRenderer r = new SimpleSeriesRenderer();
	      r.setColor(color);
	      renderer.addSeriesRenderer(r);
	    }
	    return renderer;
	  }
	  
	  
	  /**
	   * Builds a category series using the provided values.
	   * 
	   * @param titles the series titles
	   * @param values the values
	   * @return the category series
	   */
	  public  static CategorySeries buildCategoryDataset(String title, double[] values) {
	    CategorySeries series = new CategorySeries(title);
	    int k = 0;
	    for (double value : values) {
	      series.add("Project " + ++k, value);
	    }

	    return series;
	  }
	  
	  
}
